package pcjavanet.mobilesell.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import pcjavanet.mobilesell.model.Goods;
import pcjavanet.mobilesell.model.PageBean;
import pcjavanet.mobilesell.model.QryCondition;
import pcjavanet.mobilesell.service.GoodsService;

import com.opensymphony.xwork2.ActionSupport;
@Namespace("/goods")
@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Results({
	@Result(name = "success", location = "/view/Goods.jsp"),
	@Result(name = "input", location = "/view/Goods.jsp")
})

public class GoodsAction  extends ActionSupport {

  @Resource
  private GoodsService goodsService;
  private   java.lang.Integer dbid ;
  private   java.lang.String name ;
  private   java.lang.Integer refCatalogDbid ;
  private   java.lang.Integer refUnitDbid ;
  private   java.lang.Integer refConfigurationDbid ;
  private   java.lang.Integer number ;
  private   java.lang.Integer catatypeid ;
  private   java.lang.Double retailprice ;
  private   java.lang.Double lowretailprice ;
  private   java.lang.Double lowwholesaleprice ;
  private   java.lang.String pinnumber ;
  private   java.util.Date createDate ;
  private int start  ;
  private int limit  ;
  private int totalProperty  ;
  private boolean success = true ;
  private String  info ;
  private List<Goods>  goodsPageBeans  ;
  private Goods bean;
  public    java.lang.Integer getDbid() {
   	return this.dbid;
  }
  public Goods getBean() {
	return bean;
	}
	public void setBean(Goods bean) {
		this.bean = bean;
	}
	public void setDbid(  java.lang.Integer  dbid) {
	   	 this.dbid=dbid;
  }
  public    java.lang.String getName() {
   	return this.name;
  }
  public void setName(  java.lang.String  name) {
   	 this.name=name;
  }
  public    java.lang.Integer getRefCatalogDbid() {
   	return this.refCatalogDbid;
  }
  public void setRefCatalogDbid(  java.lang.Integer  refCatalogDbid) {
   	 this.refCatalogDbid=refCatalogDbid;
  }
  public    java.lang.Integer getRefUnitDbid() {
   	return this.refUnitDbid;
  }
  public void setRefUnitDbid(  java.lang.Integer  refUnitDbid) {
   	 this.refUnitDbid=refUnitDbid;
  }
  public    java.lang.Integer getRefConfigurationDbid() {
   	return this.refConfigurationDbid;
  }
  public void setRefConfigurationDbid(  java.lang.Integer  refConfigurationDbid) {
   	 this.refConfigurationDbid=refConfigurationDbid;
  }
  public    java.lang.Integer getNumber() {
   	return this.number;
  }
  public void setNumber(  java.lang.Integer  number) {
   	 this.number=number;
  }
  public    java.lang.Integer getCatatypeid() {
   	return this.catatypeid;
  }
  public void setCatatypeid(  java.lang.Integer  catatypeid) {
   	 this.catatypeid=catatypeid;
  }
  public    java.lang.Double getRetailprice() {
   	return this.retailprice;
  }
  public void setRetailprice(  java.lang.Double  retailprice) {
   	 this.retailprice=retailprice;
  }
  public    java.lang.Double getLowretailprice() {
   	return this.lowretailprice;
  }
  public void setLowretailprice(  java.lang.Double  lowretailprice) {
   	 this.lowretailprice=lowretailprice;
  }
  public    java.lang.Double getLowwholesaleprice() {
   	return this.lowwholesaleprice;
  }
  public void setLowwholesaleprice(  java.lang.Double  lowwholesaleprice) {
   	 this.lowwholesaleprice=lowwholesaleprice;
  }
  public    java.lang.String getPinnumber() {
   	return this.pinnumber;
  }
  public void setPinnumber(  java.lang.String  pinnumber) {
   	 this.pinnumber=pinnumber;
  }
  public    java.util.Date getCreateDate() {
   	return this.createDate;
  }
  public void setCreateDate(  java.util.Date  createDate) {
   	 this.createDate=createDate;
  }
  public  void setStart(int start) {
   	 this.start = start;
  }
  public  void setLimit(int limit) {
   	 this.limit = limit;
  }
  public  void setTotalProperty(int totalProperty) {
   	 this.totalProperty = totalProperty;
  }
  public  void setGoodsPageBeans(List<Goods> goodsPageBeans){
   	 this.goodsPageBeans =goodsPageBeans  ;
  }
  public  int getStart( ) {
   	 return this.start;
  }
  public  int getLimit( ) {
   	 return this.limit;
  }
  public  int getTotalProperty( ) {
   	 return this.totalProperty;
  }
  public    List<Goods> getGoodsPageBeans(){
   	 return this.goodsPageBeans   ;
  }
  public  String getInfo( ) {
   	 return this.info;
  }
  public  void setInfo(String info){
   	 this.info = info ;
  }
  public  boolean getSuccess( ) {
   	 return this.success;
  }
  public  void setSuccess(boolean success){
   	 this.success = success ;
  }

  @Action(value="insertGoods",results = {@Result(name = "success", type = "json")})
  public String  insertGoods() throws Exception{
   	success = false ;
   	info = "" ;
  	Goods bean = new Goods();
  	bean.setName(this.name); 
  	bean.setRefCatalogDbid(this.refCatalogDbid); 
  	bean.setRefUnitDbid(this.refUnitDbid); 
  	bean.setRefConfigurationDbid(this.refConfigurationDbid); 
  	bean.setNumber(this.number); 
  	bean.setCatatypeid(this.catatypeid); 
  	bean.setRetailprice(this.retailprice); 
  	bean.setLowretailprice(this.lowretailprice); 
  	bean.setLowwholesaleprice(this.lowwholesaleprice); 
  	bean.setPinnumber(this.pinnumber); 
  	bean.setCreateDate(this.createDate); 
	goodsService.insert(bean);
   	success = true ;
   	info = "Add Successful" ;
   	return SUCCESS;
  }

  @Action(value="queryGoods",results = {@Result(name = "success", type = "json")})
  public String  queryGoods() throws Exception{
	Goods  bean1 = new Goods();
	bean1.setDbid(this.dbid); 
	bean1.setName(this.name); 
	bean1.setRefCatalogDbid(this.refCatalogDbid); 
	bean1.setRefUnitDbid(this.refUnitDbid); 
	bean1.setRefConfigurationDbid(this.refConfigurationDbid); 
	bean1.setNumber(this.number); 
	bean1.setCatatypeid(this.catatypeid); 
	bean1.setRetailprice(this.retailprice); 
	bean1.setLowretailprice(this.lowretailprice); 
	bean1.setLowwholesaleprice(this.lowwholesaleprice); 
	bean1.setPinnumber(this.pinnumber); 
	bean1.setCreateDate(this.createDate); 
	bean =goodsService.selectByPrimaryKey(bean1);
   	return SUCCESS;
  }

  @Action(value="updateGoods",results = {@Result(name = "success", type = "json")})
  public String  updateGoods() throws Exception{
   	success = false ;
   	info = "" ;
  	Goods bean = new Goods();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setRefCatalogDbid(this.refCatalogDbid); 
  	bean.setRefUnitDbid(this.refUnitDbid); 
  	bean.setRefConfigurationDbid(this.refConfigurationDbid); 
  	bean.setNumber(this.number); 
  	bean.setCatatypeid(this.catatypeid); 
  	bean.setRetailprice(this.retailprice); 
  	bean.setLowretailprice(this.lowretailprice); 
  	bean.setLowwholesaleprice(this.lowwholesaleprice); 
  	bean.setPinnumber(this.pinnumber); 
  	bean.setCreateDate(this.createDate); 
  	bean =goodsService.selectByPrimaryKey(bean);
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setRefCatalogDbid(this.refCatalogDbid); 
  	bean.setRefUnitDbid(this.refUnitDbid); 
  	bean.setRefConfigurationDbid(this.refConfigurationDbid); 
  	bean.setNumber(this.number); 
  	bean.setCatatypeid(this.catatypeid); 
  	bean.setRetailprice(this.retailprice); 
  	bean.setLowretailprice(this.lowretailprice); 
  	bean.setLowwholesaleprice(this.lowwholesaleprice); 
  	bean.setPinnumber(this.pinnumber); 
  	bean.setCreateDate(this.createDate); 
	goodsService.updateByPrimaryKeySelective(bean);
   	success = true ;
   	info = "Update Successful" ;
   	return SUCCESS;
  }

  @Action(value="deleteGoods",results = {@Result(name = "success", type = "json")})
  public String  deleteGoods() throws Exception{
  	Goods bean = new Goods();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setRefCatalogDbid(this.refCatalogDbid); 
  	bean.setRefUnitDbid(this.refUnitDbid); 
  	bean.setRefConfigurationDbid(this.refConfigurationDbid); 
  	bean.setNumber(this.number); 
  	bean.setCatatypeid(this.catatypeid); 
  	bean.setRetailprice(this.retailprice); 
  	bean.setLowretailprice(this.lowretailprice); 
  	bean.setLowwholesaleprice(this.lowwholesaleprice); 
  	bean.setPinnumber(this.pinnumber); 
  	bean.setCreateDate(this.createDate); 
	goodsService.deleteByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="listGoods",results = {@Result(name = "success", type = "json")})
  public String  listGoods() throws Exception{
 	QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
	pageBean.setPageSize( limit );
	pageBean.setStartCount( start );
	totalProperty =goodsService.getTotalRecords( qry, pageBean );
	goodsPageBeans =goodsService.getOnePageBeans( qry, pageBean );
   	return SUCCESS;
  }

  @Action("index")
  public String index() throws Exception{
   	return SUCCESS;
  }

}
